$(function(){
    // $(".indexLogin").click(function() {
    //     var d = dialog({
    //         title: '登录',
    //         url:'/user/user/loginRegister'
    //     });
    //     d.showModal();
    //     $(".ui-dialog-header").attr("id", "index-ui-bg");
    //     $(".ui-dialog-title").css({
    //         "font-size" : "22px",
    //         "color" : "#666666",
    //         "font-weight" : "normal"
    //     });
    //    $(".ui-dialog-grid input").focus(function() {
    //        $(".login-content .login-account").css({
    //            "border" : "1px solid #cfcfcf"
    //        });

    //        $(".login-content .login-pw").css({
    //            "border" : "1px solid #cfcfcf"
    //        })
    //        $(this).parent().css({
    //            "border" : "1px solid #ff7694"
    //        });
    //    })
    // })








	//左侧楼层导航
	
	function scrollToTop(parentId) {
		var indexWrapper = document.getElementById(parentId),
			indexNav = document.getElementById('indexNav'),
			iscrollTop = document.documentElement.scrollTop || document.body.scrollTop,
			wrapperLeft = indexWrapper.offsetLeft,
			wrapperWidth = indexWrapper.clientWidth,
			navWidth = indexNav.offsetWidth,
			indexNavR = document.getElementById('indexNavR'),
			timer = null;


			
			indexNav.style.left = parseInt(wrapperLeft - 100 - 10) + 'px';
			indexNavR.style.left = parseInt(wrapperLeft + wrapperWidth + 10) + 'px';

			


			
			$("#indexNav li:last").click(function() {
				$("html,body").stop(true, true).animate({
					"scrollTop" : "0"
				},600);

			})

			window.onscroll = function() {
				var iscrollTop = document.documentElement.scrollTop || document.body.scrollTop;
				if(iscrollTop>= 1000) {
					$(indexNav).css({
						"opacity" : "1"
					});

					$(indexNavR).css({
						"opacity" : "1"
					});
				} else {
					
					$(indexNav).css({
						"opacity" : "0"
					});
					$(indexNavR).css({
						"opacity" : "0"
					})
				}
				
				$("#indexNav ul li").click(function(){
					var index = $(this).index(),
						dis = 1140 + parseInt(index * 869);
						iscrollTop = dis;
						document.documentElement.scrollTop = iscrollTop;
						document.body.scrollTop = iscrollTop;
				})
			}
			
			window.onresize = function() {
				var wrapperLeft = indexWrapper.offsetLeft,
					navWidth = indexNav.offsetWidth;
				indexNav.style.left = parseInt(wrapperLeft - 100) + 'px';
				indexNavR.style.left = parseInt(wrapperLeft + wrapperWidth + 10) + 'px';

			}
	}
	scrollToTop('indexWrapper');



    var parentIndex = $(".index-floor .index-floor1").index();
/*	$(" .index-floor1-hover li").mouseover(function(){

	})*/

	

	var ulLength = $(".index-box-ad-content ul").length - 1,
		boxWidth = $(".index-box-ad-content ul").outerWidth(),
		totleWidth = boxWidth * (ulLength + 1),
		contentWidth = $(".index-box-ad-content").outerWidth();
	$(".index-box-ad-content").width(totleWidth);
	
	
	$(".index-floor1-tit a").mouseover(function() {
		$(this).siblings("strong").css({
			"background" : "url(/themes/mmj/assets/images/icon.png" + ") -51px -13px"
		});
	});
	$(".index-floor1-tit a").mouseout(function() {
		$(this).siblings("strong").css({
			"background" : "url(/themes/mmj/assets/images/icon.png" + ") -51px 0px"
		});
	})

	$(".index-bar p").mouseover(function() {
		$(this).siblings(".index-ad-arrow").css({
			"background" : "url(/themes/mmj/assets/images/arrow-r_1.png" + ")"
		});
	});
	$(".index-bar p").mouseout(function() {
		$(this).siblings(".index-ad-arrow").css({
			"background" : "url(/themes/mmj/assets/images/arrow-r.png" + ")"
		});
	})

	function moveStart(){

			var i = 0,
				j = 0,
				dis = null,
				moveJudge = true;
		function movePic() {
			i--;
			if(i < -ulLength) {
				i = 0;
				$(".index-box-ad-content").animate({
					"left" : 0
				},600);
			} else {
				dis = 570 * i;
				$(".index-box-ad-content").animate({
					"left" : dis
				},600);
			}
		}

			timer = setInterval(movePic, 2500);
			
		$(".index-box-ad-l").mouseover(function() {
			clearInterval(timer);
		});

		$(".index-box-ad-l").mouseout(function() {
			timer = setInterval(movePic, 2500);
		});

        $("#arrowLeft").click(function() {
            clearInterval(timer);
            if(i == -ulLength) {
                i = 0;
                $(".index-box-ad-content").stop(true, true).animate({
                    "left" : "0"
                },400)
            }
            else {
                i--;
                dis = 570 * i;
                $(".index-box-ad-content").stop(true, true).animate({
                    "left" : dis + "px"
                },400);
            }
        });

        $("#arrowRight").click(function() {
            clearInterval(timer);
            if( i == 0) {
                i = -ulLength;
                dis = 570 * i;
                $(".index-box-ad-content").stop(true, true).animate({
                    "left" : dis + "px"
                },400)
            } else {
                i++;
                dis = 570 * i;
                $(".index-box-ad-content").stop(true, true).animate({
                    "left" : dis + "px"
                },400);
            }
        });

	}

	moveStart();

	// 顶部图片轮播
function banner(){	
	var bn_id = 0;
	var bn_id2= 1;
	var speed33=5000;
	var qhjg = 1;
    var MyMar33;
	$(".index-nav-r1-t a").hide();
	$(".index-nav-r1-t a").eq(0).fadeIn("slow");
	if($(".index-nav-r1-t a").length>1)
	{
		$("#banner_id li").eq(0).addClass("nuw");
		function Marquee33(){
			bn_id2 = bn_id+1;
			if(bn_id2>$(".index-nav-r1-t a").length-1)
			{
				bn_id2 = 0;
			}
			$(".index-nav-r1-t a").eq(bn_id).css("z-index","2");
			$(".index-nav-r1-t a").eq(bn_id2).css("z-index","1");
			$(".index-nav-r1-t a").eq(bn_id2).show();
			$(".index-nav-r1-t a").eq(bn_id).fadeOut("slow");
			$("#banner_id li").removeClass("nuw");
			$("#banner_id li").eq(bn_id2).addClass("nuw");
			bn_id=bn_id2;
		};
	
		MyMar33=setInterval(Marquee33,speed33);
		
		$("#banner_id li").click(function(){
			var bn_id3 = $("#banner_id li").index(this);
			if(bn_id3!=bn_id&&qhjg==1)
			{
				qhjg = 0;
				$(".index-nav-r1-t a").eq(bn_id).css("z-index","2");
				$(".index-nav-r1-t a").eq(bn_id3).css("z-index","1");
				$(".index-nav-r1-t a").eq(bn_id3).show();
				$(".index-nav-r1-t a").eq(bn_id).fadeOut("slow",function(){qhjg = 1;});
				$("#banner_id li").removeClass("nuw");
				$("#banner_id li").eq(bn_id3).addClass("nuw");
				bn_id=bn_id3;
			}
		})
		$("#banner_id").hover(
			function(){
				clearInterval(MyMar33);
			}
			,
			function(){
				MyMar33=setInterval(Marquee33,speed33);
			}
		)	
	}
	else
	{
		$("#banner_id").hide();
	}
}

banner();

//    弹出框

//    var dialog = require('./src/dialog');




	// 支持placeholder属性
	  var JPlaceHolder = {
    //检测
    _check : function(){
        return 'placeholder' in document.createElement('input');
    },
    //初始化
    init : function(){
        if(!this._check()){
            this.fix();
        }
    },
    //修复
    fix : function(){
        jQuery(':input[placeholder]').each(function(index, element) {
            var self = $(this), txt = self.attr('placeholder');
            self.wrap($('<div></div>').css({position:'relative', zoom:'1', border:'none', background:'none', padding:'none', margin:'none'}));
            var pos = self.position(), h = self.outerHeight(true), paddingleft = self.css('padding-left');
            var holder = $('<span></span>').text(txt).css({position:'absolute', left:pos.left, top:pos.top="6px", height:h, lienHeight:h, paddingLeft:paddingleft, color:'#aaa'}).appendTo(self.parent());
            self.focusin(function(e) {
                holder.hide();
            }).focusout(function(e) {
                if(!self.val()){
                    holder.show();
                }
            });
            holder.click(function(e) {
                holder.hide();
                self.focus();
            });
        });
    }
};
//执行
jQuery(function(){
    JPlaceHolder.init();  
});

})


